/**
 * 
 */
package com.pmsco.pms.core.domain;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

/**
 * @author Long Tran
 *
 */
@Entity
@Table(
	name = "PMS_MENU"
)
public class PmsMenu {
	private Long id;
	private String name;
	private String url;
	private String isLogonRequired;
	private String isTopLevel;
	private Long orderId;
	private List<PmsMenu> children;
	private PmsMenu parent;
	
	public static String className = "PmsMenu";
	public static String orderIdField = "orderId";
	public static String isTopLevelField = "isTopLevel";
	public static String idField = "id";
	public static String nameField = "name";
	
	/**
	 * @return the id
	 */
	@Id
	@GeneratedValue
	@Column(name = "ID", nullable = false)
	public Long getId() {
		return id;
	}
	
	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}
	
	/**
	 * @return the name
	 */
	@Column(name = "NAME", nullable = false)
	public String getName() {
		return name;
	}
	
	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}
	
	/**
	 * @return the url
	 */
	@Column(name = "URL", nullable = false)
	public String getUrl() {
		return url;
	}
	
	/**
	 * @param url the url to set
	 */
	public void setUrl(String url) {
		this.url = url;
	}
	
	/**
	 * @return the isLogonRequired
	 */
	@Column(name = "IS_LOGON_REQUIRED", nullable = false)
	public String getIsLogonRequired() {
		return isLogonRequired;
	}
	
	/**
	 * @param isLogonRequired the isLogonRequired to set
	 */
	public void setIsLogonRequired(String isLogonRequired) {
		this.isLogonRequired = isLogonRequired;
	}
	
	/**
	 * @return the isTopLevel
	 */
	@Column(name = "IS_TOP_LEVEL", nullable = false)
	public String getIsTopLevel() {
		return isTopLevel;
	}
	
	/**
	 * @param isTopLevel the isTopLevel to set
	 */
	public void setIsTopLevel(String isTopLevel) {
		this.isTopLevel = isTopLevel;
	}
	
	/**
	 * @return the orderId
	 */
	@Column(name = "ORDERID", nullable = false)
	public Long getOrderId() {
		return orderId;
	}

	/**
	 * @param orderId the orderId to set
	 */
	public void setOrderId(Long orderId) {
		this.orderId = orderId;
	}
	
	/**
	 * @return the children
	 */
	@OneToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "PMS_MENU_STRUCTURE", joinColumns = {@JoinColumn(name = "PARENT_ID", nullable = false, insertable = false, updatable = false)}, 
	inverseJoinColumns = {@JoinColumn(name = "CHILD_ID", nullable = false, insertable = false, updatable = false)})
	@OrderBy(value = "orderId")
	public List<PmsMenu> getChildren() {
		return children;
	}

	/**
	 * @param children the children to set
	 */
	public void setChildren(List<PmsMenu> children) {
		this.children = children;
	}
	
	/**
	 * @return the parent
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinTable(name = "PMS_MENU_STRUCTURE", joinColumns = {@JoinColumn(name = "CHILD_ID", nullable = false, insertable = false, updatable = false)}, 
	inverseJoinColumns = {@JoinColumn(name = "PARENT_ID", nullable = false, insertable = false, updatable = false)})
	public PmsMenu getParent() {
		return parent;
	}

	/**
	 * @param parent the parent to set
	 */
	public void setParent(PmsMenu parent) {
		this.parent = parent;
	}
	
}
